All right.
So now I'm going to point out something that you may have noticed, may not have, but you will eventually.
If I shoot my other player and the body, we do damage.
If I shoot him in the head, we don't.
Right hand.
Fine foot.
Fine head.
No, that's because of the hair.
There's an accessory and the hair is an accessory.
But we're going to have trouble with, like, backpacks and things like that.
So we're going to have to take care of accessories for our simple pistol.
There are a lot of ways of dealing with accessories when you're making a weapon, but I wanted a way
that's going to work with recast weapons, which we haven't made yet.
Mouse click weapons, which we have one of and I didn't want to get in and change the code in my pistol.
So how do I do that?
I'm going to go to game manager.
I haven't seen a lot of people do this, actually.
I've never seen anybody do this, but I think it's a really good idea and it works.
I'm going to make a function above that player added event.
I'm going to call this exclude
accessory and then I'm going to pass my part in that.
We're going to check to see if it's an accessory.
The part I'm going to say, if part is a accessory, then let's take a look at everything underneath
that part.
Like there's going to be a handle and stuff like that.
Let's say for R and V in pairs part get children
do.
If V is a base part, then so like think of our pistol, right?
Our pistol is a tool which is similar to an accessory.
It's got a handle on it and it's got that gun part, which is a mesh part.
Those parts can block our casting in our clicks.
So all of those parts that can block that are bass parts or some sort of subcategory of bass part,
then what we're going to do is we're going to make sure that can collide is false.
Now handles are they can collide becomes false anyway.
But if can collide is false, then we can turn something called can query as false.
And this is what indicates whether you can query something with a ray cast or a mouse click.
If we make it false, that accessory becomes invisible to our mouse click and our array cast.
All right.
But we're not using the array cast yet.
Now, underneath, underneath this player added, Let's see.
Where is that?
Right here.
Yes.
Let's do a player dot character appearance loaded.
This fires after the character is added.
We want to make sure there's clothes on and stuff and then we're going to connect to an anonymous function.
The char is going to get passed in and we're going to say for I and V in pairs of our char, we're going
to get children.
Accessory is on one level down.
So to get children to work do so the V is the part I as the counter V's are.
The V is the part that's underneath the character.
We're going to do exclude accessory pass in the V.
Now, unfortunately, sometimes all the parts aren't loaded.
This will fire and it'll exclude some parts.
So let's get our char hook up our descendant added event by connecting it to an anonymous function.
The part that got added after where this triggered is going to be one of the arguments.
I'm going to get my exclude accessory and pass that in to just to make sure nothing sneaked pass our
for loop right then we're going to do that.
Now we should be able to fire our our pistol and hit somebody in the head.
Let's go to our test hit the start with two players playing.
I'm going to pause video.
It starts up.
All right, here we go.
Let's try it out.
Wait for my bubble to go away.
His bubble go away.
Boom.
We got them.
We got them ready to pile here.
No problemo.
All right, so we solve that problem.
That's pretty cool.